home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / WINDOWS / MSJV7_1.ARJ / HPEEP1.C < prev    next >
Text File  |  1992-01-01  |  7KB  |  228 lines

  1. //   HeapPeep (c) 1991 Chiverton Graphics, Inc.
  2. //
  3. //               Microsoft Windows Debugging Utility
  4. //
  5. //
  6. #include <windows.h>
  7. #include "hpeep2.h"
  8.  
  9.  
  10. #define IDM_ABOUT   1
  11. #define IDD_LOGO  101
  12.  
  13.  
  14. long  FAR PASCAL WndProc      (HWND hWnd, unsigned message, WORD wParam,
  15.                                                             LONG lParam);
  16. BOOL  FAR PASCAL AboutDlgProc (HWND hWnd, unsigned message, WORD wParam,
  17.                                                             LONG lParam);
  18.  
  19.  
  20. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine,
  21.                                                               int nCmdShow)
  22.      {
  23.      MSG      msg;
  24.      WNDCLASS wc;
  25.      HWND     hwnd;
  26.  
  27.  
  28.   if (hwnd = FindWindow ("HeapPeep_ToolHelp", NULL))
  29.      {
  30.      // Found another running application with the same class
  31.      // name... so one instance is already running. Don't run a 2nd instance.
  32.  
  33.      BringWindowToTop (hwnd);
  34.      return (FALSE);
  35.      }
  36.  
  37.      wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
  38.      wc.hIcon         = LoadIcon (hInstance, "HeapPeep");
  39.      wc.cbClsExtra    = 0;
  40.      wc.cbWndExtra    = 0;
  41.      wc.lpszMenuName  = NULL;
  42.      wc.lpszClassName = "HeapPeep_ToolHelp";
  43.      wc.hbrBackground = GetStockObject (WHITE_BRUSH);
  44.      wc.hInstance     = hInstance;
  45.      wc.style         = CS_VREDRAW | CS_HREDRAW;
  46.      wc.lpfnWndProc   = WndProc;
  47.  
  48.      RegisterClass (&wc);
  49.  
  50.      hwnd = CreateWindow ("HeapPeep_ToolHelp",
  51.                           "HeapPeep",
  52.                           WS_OVERLAPPEDWINDOW,
  53.                           CW_USEDEFAULT, 0,
  54.                           CW_USEDEFAULT, 0,
  55.                           NULL, NULL, hInstance,
  56.                           NULL);
  57.  
  58.  
  59.      //    set up timer (2 updates/sec)
  60.      //
  61.      if (!SetTimer (hwnd, 1, 500, NULL))
  62.           {
  63.           MessageBox (GetFocus(), "Too many Timers or Clocks!",
  64.                                   "HeapPeep", MB_OK | MB_SYSTEMMODAL);
  65.           return (FALSE);
  66.           }
  67.  
  68.      ShowWindow (hwnd, nCmdShow);
  69.  
  70.      while (GetMessage (&msg, NULL, 0, 0))
  71.           {
  72.           TranslateMessage (&msg);
  73.           DispatchMessage  (&msg);
  74.           }
  75.  
  76.      return (int) msg.wParam;
  77.      }
  78.  
  79.  
  80.  
  81. BOOL FAR PASCAL AboutDlgProc (HWND hDlg, unsigned m, WORD w, LONG l)
  82.      {
  83.      static HBITMAP hbm;
  84.  
  85.      switch (m)
  86.           {
  87.           case WM_INITDIALOG:
  88.                {
  89.                int cxScreen, cyScreen, cxDialog, cyDialog;
  90.                RECT rcDialog;
  91.  
  92.                //
  93.                //   Create the logo bitmap, and
  94.                //   center the dialogbox on the display.
  95.                //
  96.                hbm = LoadBitmap (GetWindowWord (hDlg, GWW_HINSTANCE), "logo");
  97.  
  98.  
  99.                //   Get the Display size
  100.                //
  101.                cxScreen = GetSystemMetrics (SM_CXSCREEN);
  102.                cyScreen = GetSystemMetrics (SM_CYSCREEN);
  103.  
  104.                //   Get the DialogBox size
  105.                //
  106.                GetWindowRect (hDlg, &rcDialog);
  107.                cxDialog = rcDialog.right  - rcDialog.left;
  108.                cyDialog = rcDialog.bottom - rcDialog.top ;
  109.  
  110.                SetWindowPos (hDlg, NULL, (cxScreen - cxDialog)/2, // x
  111.                                          (cyScreen - cyDialog)/2, // y
  112.                                           cxDialog,               // cx
  113.                                           cyDialog,               // cy
  114.                                           SWP_NOZORDER);
  115.                }
  116.                return FALSE;
  117.  
  118.           case WM_PAINT:
  119.                {
  120.                HDC hdcMem;
  121.                PAINTSTRUCT ps;
  122.                HBITMAP hbmOld;
  123.                HWND hwndLogo;
  124.                RECT rcLogo,
  125.                     rcDialog;
  126.                int  x,y;
  127.  
  128.                BeginPaint (hDlg, &ps);
  129.  
  130.                hdcMem = CreateCompatibleDC (ps.hdc);
  131.                hbmOld = SelectObject (hdcMem, hbm);
  132.  
  133.                SetTextColor (ps.hdc, RGB (255, 0, 255));
  134.  
  135.                hwndLogo = GetDlgItem (hDlg, IDD_LOGO);
  136.                GetWindowRect (hwndLogo, &rcLogo);
  137.                GetWindowRect (hDlg,     &rcDialog );
  138.                x = rcLogo.left - rcDialog.left;
  139.                y = rcLogo.top  - rcDialog.top ;
  140.  
  141.                BitBlt (ps.hdc, x, y, 200, 200, hdcMem, 0, 0, SRCCOPY);
  142.                SelectObject (hdcMem, hbmOld) ;
  143.                DeleteDC (hdcMem);
  144.  
  145.                EndPaint (hDlg, &ps);
  146.  
  147.                return FALSE;
  148.                }
  149.  
  150.           case WM_DESTROY:
  151.                DeleteObject (hbm);
  152.                return FALSE;
  153.  
  154.           case WM_COMMAND:
  155.                EndDialog (hDlg, 0);
  156.                return TRUE;
  157.           }
  158.  
  159.      return FALSE ;
  160.      }
  161.  
  162.  
  163.  
  164. long FAR PASCAL WndProc (HWND hwnd, unsigned message, WORD wParam, LONG lParam)
  165.      {
  166.      switch (message)
  167.           {
  168.           case WM_CREATE:
  169.                {
  170.                HMENU hMenu    = GetSystemMenu (hwnd, FALSE);
  171.                int   cxScreen = GetSystemMetrics (SM_CXSCREEN),
  172.                      cyScreen = GetSystemMetrics (SM_CYSCREEN);
  173.  
  174.                dds_create (hwnd);
  175.  
  176.  
  177.                //   Add "About Heappeep..." to system menu
  178.  
  179.                ChangeMenu (hMenu, 0, NULL, 0, MF_APPEND);
  180.                ChangeMenu (hMenu, 0, "A&bout Heappeep...", IDM_ABOUT,
  181.                                                            MF_APPEND);
  182.  
  183.  
  184.                //   Position the window in the lower 1/3 of the display.
  185.  
  186.                SetWindowPos (hwnd, NULL, 0,                 // x
  187.                                          (2 * cyScreen)/3,  // y
  188.                                          cxScreen,          // cx
  189.                                          cyScreen/3,        // cy
  190.                                          SWP_NOZORDER);
  191.                }
  192.                return  0L;
  193.  
  194.           case WM_TIMER:
  195.                dds_walk ();
  196.                return 0L;
  197.  
  198.           case WM_SYSCOMMAND:
  199.                if (wParam == IDM_ABOUT)
  200.                     {
  201.                     HANDLE  hInstance = (HANDLE)GetWindowWord (hwnd,
  202.                                                       GWW_HINSTANCE);
  203.                     FARPROC lpfn      = MakeProcInstance ((FARPROC)AboutDlgProc,
  204.                                                                      hInstance);
  205.  
  206.                     DialogBox (hInstance, "AboutBox", hwnd, lpfn);
  207.                     FreeProcInstance (lpfn) ;
  208.                     return 0L;
  209.                     }
  210.                break;
  211.  
  212.           case WM_PAINT:
  213.                dds_paint ();
  214.                return  0L;
  215.  
  216.           case WM_DESTROY:
  217.                dds_destroy ();
  218.                KillTimer (hwnd, 1);
  219.                PostQuitMessage (0);
  220.                return  0L;
  221.  
  222.           default:
  223.                break;
  224.           }
  225.  
  226.      return DefWindowProc (hwnd, message, wParam, lParam);
  227.      }
  228.